package com.itheima.tcpdemo02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //TCP Socket 服务端

        //1.创建 Socket
        ServerSocket socket = new ServerSocket(10002);

        //2.等待客服端连接
        Socket accept = socket.accept();

        //3.读取数据
        InputStream stream = accept.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);

        int b;

        while ((b = reader.read()) != -1) {
            System.out.print((char) b);
        }

        //5.向客服端回复数据
        String str = "都很好！！！";
        OutputStream os = accept.getOutputStream();
        os.write(str.getBytes());

        //4.释放资源
        stream.close();
        socket.close();


    }
}
